﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ToolS
{
    public class RequestEntityHelper
    {
        private static string BasePath { get { return Init.workPath; } }

        public static RequestEntity LoadRequestEntity(PathEntity pathEntity)
        {
            string requestXml = FileHelper.GetFileString(BasePath+"/requests/"+ pathEntity.ParentPath);
            var requestEntity = XmlHelper.Deserialize<RequestEntity>(requestXml);
            return requestEntity;
        }

        public static void SaveRequestEntity(PathEntity pathEntity , RequestEntity requestEntity)
        {
            string requestXml = XmlHelper.ObjectSerialize(requestEntity);
            FileHelper.WriteFile(BasePath + "/requests/" + pathEntity.ParentPath, requestXml);
        }

        public static WorkSettings GetWorkSetting()
        {
            string xmlSetting = FileHelper.GetFileString(BasePath + "/" + WorkSettings.name);
            WorkSettings setting = XmlHelper.Deserialize<WorkSettings>(xmlSetting);
            return setting;
        }

        public static bool SaveWorkSetting(WorkSettings setting)
        {
            try
            {
                string xmlSetting = XmlHelper.ObjectSerialize(setting);
                FileHelper.WriteFile(BasePath + "/" + WorkSettings.name, xmlSetting);
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }

        }
    }
}
